<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>角色管理</title>
    <link rel="stylesheet" href="__LAY__/css/layui.css" media="all">
    <link rel="stylesheet" href="__CSS__/main.css" media="all">
    <link rel="stylesheet" href="__FONT__/css/font-awesome.min.css" media="all" />
</head>
<body>
<div class="right_body">
    <div class="right_content_top">
        <blockquote class="layui-elem-quote">
            <a href="{:url('role/addrole')}" class="layui-btn">添加</a>
            <!--<button class="layui-btn  layui-btn-normal">搜索</button>-->
        </blockquote>
    </div>
    <div style="text-align: center;">
        <div class="layui-inline">
            <table id="demo" lay-filter="test"></table>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="__JS__/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="__LAY__/layui.js"></script>
<script type="text/javascript" src="__JS__/index.js"></script>
<script src="https://cdn.bootcss.com/limonte-sweetalert2/7.21.1/sweetalert2.all.js"></script>
<script>
    function initTable(){
        layui.use('table', function(){
            var table = layui.table;
            //第一个实例
            table.render({
                elem: '#demo'
                ,height: 500
                ,url: "{:url('role/index')}" //数据接口
                ,page: true //开启分页
                ,cols: [[ //表头
                    {field: 'role_id', title: 'ID',width:60,unresize:true,align:'center'}
                    ,{field: 'role_name', title: '角色名称',unresize:true,align:'center'}
                    ,{field: 'operate', title: '操作',unresize:true,align:'center'}
                ]]
            });

        });
    }
    $(document).ready(function () {
        //调用函数，初始化表格
        initTable();
    });
    function roleDel(id){
        swal({
            title: "确定删除吗？",
            text: "删除后将无法恢复",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定删除！",
            cancelButtonText: "取消删除！",
            closeOnConfirm: false,
            closeOnCancel: false

        })
        .then(function(isConfirm){
            if(isConfirm.value) {
                $.getJSON("{:url('role/roledel')}", {'role_id' : id}, function(res){
                    if(1 == res.code){
                        swal("干得漂亮！", res.msg,"success");
                        initTable();
                    }else if(111 == res.code){
                        window.location.reload();
                    }else{
                        layer.alert(res.msg, {title: '友情提示', icon: 2});
                    }
                });
            } else {
                swal("取消！", "感谢您没有把我删除奥","error");
            }
        });
    }

    function distribution(id)
    {
        var url =   window.location.pathname;
        tmpHPage = url.split( "/" );
        tmpHPage.pop();
        url =  tmpHPage.join("/");
        layer.open({
            title : "分配权限",
            type : 2,
            area: ['60%','80%'], //宽高
            content : url+"/distribution?id="+id
        });
    }



</script>
</html>